package com.zwh.se.collection.concurrent;

import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @author yexi
 */
@SuppressWarnings("all")
public class CopyOnWriteArraySetDemo {
    public static void main(String[] args) {
        CopyOnWriteArraySet<Integer> copyOnWriteArraySet = new CopyOnWriteArraySet<>();
        //Set和List的本质区别:无论怎样都不可以重复
        copyOnWriteArraySet.add(1);
        copyOnWriteArraySet.add(2);
        copyOnWriteArraySet.add(2);
        copyOnWriteArraySet.add(7);
        //[1, 2, 7]
        System.out.println(copyOnWriteArraySet);

        System.out.println("----------------------CopyOnWriteArraySet的底层分析----------------------");
        /**
         * 其底层直接基于CopyOnWriteArrayList
         * @see CopyOnWriteArraySet#CopyOnWriteArraySet()
         *         al = new CopyOnWriteArrayList<E>();
         * @see CopyOnWriteArraySet#al
         *
         * 底层直接调用 CopyOnWriteArrayList 的 addIfAbsent 就实现了
         * @see CopyOnWriteArraySet#add(Object)
         *         return al.addIfAbsent(e);
         */
        copyOnWriteArraySet.add(7);

    }
}
